<cfparam name="report" type="string" default="howDidWeDo" />
<cfif report eq "howDidWeDo">
	<cfset sourcePath = "http://" & cgi.HTTP_HOST & "/assets/calgrants/ui/printable/howDidWeDo.cfm" />
	<cfset targetDirectory = "C:\inetpub\assets\calgrants\reports\hdwd\" />
	<cfset targetPath = "http://" & cgi.HTTP_HOST & "/assets/calgrants/reports/hdwd/" />
	<cfset filenameRoot = "CashForCollege_HowDidWeDo_2013_" />
	<cfset qString = cgi.QUERY_STRING />
	<cfloop index="i" from="1" to="#ListLen(qString, '&')#">
		<cfset kvp = ListGetAt(qString, i, "&") />
		<cfif ListLast(ListFirst(kvp, "="), "_") eq "id">
			<cfset fileIdentifier = ListFirst(ListFirst(kvp, "="), "_") & "_" & ListLast(kvp, "=") />
			<cfbreak>
		</cfif>
	</cfloop>
	<cfif NOT IsDefined("fileIdentifier")>
		<cfset fileIdentifier = "Statewide" />
	</cfif>
	<cfset filename = filenameRoot & fileIdentifier & ".pdf" />
	<cfset sourceURL = sourcePath & "?" & cgi.QUERY_STRING />
	<cfset targetFile = targetDirectory & filename />
	<cfset targetURL = targetPath & filename />
</cfif>
<cfif IsDefined("targetFile") and IsDefined("targetURL")>
	<cfif NOT FileExists(targetFile)>
		<h1>Please wait while we generate the report</h1>
		<cfset pjsExe = "C:\Program Files (x86)\phantomjs\phantomjs.exe" />
		<cfset pjsScript = "C:\inetpub\assets\phantomjs\examples\rasterize.js" />
		<cfset pjsArgs = pjsScript & " " & sourceURL & " " & targetFile & " Letter" />
		<cfexecute name="#pjsExe#" arguments="#pjsArgs#" />
		<script type="text/javascript">
			<cfoutput>
				window.setTimeout(
					funtion() {
						window.location = "#targetURL#";
					},
				10000);
			</cfoutput>
		</script>
	<cfelse>
		<cflocation url="#targetURL#" addtoken="no">
	</cfif>
<cfelse>
	<h1>Invalid report request</h1>
</cfif>
<cfsetting showdebugoutput="no" />
